import 'package:share_fit/app/models/base_model.dart';

class SportState extends BaseModel {
  /// 执行状态
  int? operatorType;

  /// 单次运动类型，具体见 WorkoutType
  int? workoutType;

  /// 运动监测占用状态(Motion monitoring status)
  /// 1 占用， 0 空闲
  int? monitorState;

  /// 运动分类, 1 单次运动 ，2 跑步计划
  int? sportType;

  /// 跑步计划起始日期，格林尼治时间，单位：秒
  int? startDate;

  static const int no = 0; //未开启运动Not started
  static const int start = 1; //开始运动Start
  static const int pause = 2; //暂停运动Pause
  static const int continuing = 3; //继续运动Continue
  static const int finish = 4; //结束运动Finish
  static const int started = 5; //运动已开始Started
  static const int paused = 6; //运动已暂停Paused
  static const int noStarted = 7; //运动未启动Not started

  SportState({this.operatorType, this.workoutType, this.monitorState, this.sportType, this.startDate});

  @override
  bool from(Map map) {
    try {
      operatorType = map['operatorType'];
      workoutType = map['workoutType'];
      monitorState = map['monitorState'];
      sportType = map['sportType'];
      startDate = map['startDate'];
    } catch (e) {
      return false;
    }
    return true;
  }

  bool isPause() {
    return operatorType == pause || operatorType == paused;
  }

  bool canStart() {
    return no == operatorType || noStarted == operatorType;
  }

  bool canPause() {
    return start == operatorType || started == operatorType;
  }

  bool canContinue() {
    return paused == operatorType || pause == operatorType;
  }

  bool isFinished() {
    return operatorType == finish;
  }

  bool inProcess() {
    return no != operatorType && finish != operatorType && noStarted != operatorType;
  }

  @override
  List<Object?> get props => [operatorType, workoutType, monitorState, sportType, startDate];

  @override
  bool? get stringify => true;
}
